#Code corresponding to "main" debates model in Eggers & Spirling, "Ministerial
# Responsiveness in Westminster Systems", forthcoming at AJPS 

#written by Arthur Spirling (aspirling@gov.harvard.edu)
#on Oct 24, 2013

#requires: dat.big.rdata, which contains the relevant data frame
#requires: MCMCglmm package  


rm(list=ls())

# the data: a 534627*4 matrix with columns corresponding to "y" which is the 
# next speaker (status), "x" which is the current speaker (status), debate 
# number (which has a random effect in the model) and "ministry" (which also 
# has a random effect
load("dat.big.rdata")

#the requisite package
require(MCMCglmm)


#give the priors
priors <- list(R = list(V = diag(2), nu = 0.002, n=0, fix=1), 
G = list(
G1=list(V = diag(6)*0.02, nu =7),
G2=list(V=diag(6)*0.02, nu=7)
)
)


#fit the model, note the thinning.
#(have wrapped code for presentation, but you may need to "unwrap" depending on
# on your R editor)
mod.mc.full <- MCMCglmm(ys~trait+trait:xs - 1, random= 
~us(trait+trait:xs):debate+ us(trait+trait:xs):ministry,  
rcov=~us(trait):units, family='categorical', data=dat.big, burnin=10000, 
nitt=60000, pr=T, prior=priors, thin=100)

#predicted (i.e. transition) probabilities are based on "usual" auxillary 
#qty calculation for this class of models: see SI appendix for full details 
